$(function(){
  $('.layui-nav-item>a').click(function(){
    if($(this).html() == '个人中心'){
      $('.xs-home').show();
      $('.xs-score').hide();
      $('.xs-select').hide();
      $('.xs-search').hide();
    }
    if($(this).html() == '学籍成绩'){
      $('.xs-home').hide();
      $('.xs-score').show();
      $('.xs-select').hide();
      $('.xs-search').hide();
    }
    if($(this).html() == '已选课程'){
      $('.xs-home').hide();
      $('.xs-score').hide();
      $('.xs-select').show();
      $('.xs-search').hide();
    }
    if($(this).html() == '选课查询'){
      $('.xs-home').hide();
      $('.xs-score').hide();
      $('.xs-select').hide();
      $('.xs-search').show();
    }

    
  })

  $.ajax({
    url: "http://ce.shi/xuanke/",
    type: "post",
    dataType: "JSON",
    data: {
      page: 1,
    },
    cache: false, //同步请求
    ContentType: "application/xml;charset=utf-8",
    success: function (res) {
      var str = 'javascript:;';
      // CouNo 课程编号
      // CouName  课程名称
      // Kind   课程类别
      // Credit  学分
      // Teacher 任课教师
      // SchoolTime 上课时间
      $('.course-info').empty();
      for(i=0;i<5;i++){
        $('.course-info').append("<tr><td>"+res[i]['CouNo']+"</td><td>"+res[i]['CouName']+"</td><td>"+res[i]['Kind']+"</td><td>"+res[i]['Credit']+"</td><td>"+res[i]['Teacher']+"</td><td>"+res[i]['SchoolTime']+"</td><td><a href=info.html?course="+res[i]['CouNo']+" class='detail'>查看</a></td></tr>");
      }
      // console.log(res[0]['CouNo'])
      // console.log(res[0]['CouName'])
      // console.log(res[0]['Kind'])
      // console.log(res[0]['Credit'])
      // console.log(res[0]['Teacher'])
      // console.log(res[0]['SchoolTime'])
    },
    error: function (err) {
      console.log('请求失败')
    }
  });

  $('#demo2').click(function(){
    var page = $('#demo2 .layui-laypage-curr :nth-child(2)').html();

    // 进行课程查询
    $.ajax({
      url: "http://ce.shi/xuanke/",
      type: "post",
      dataType: "JSON",
      data: {
        page: page,
      },
      cache: false, //同步请求
      ContentType: "application/xml;charset=utf-8",
      success: function (res) {
        // var str = 'javascript:;';
        // CouNo 课程编号
        // CouName  课程名称
        // Kind   课程类别
        // Credit  学分
        // Teacher 任课教师
        // SchoolTime 上课时间
        $('.course-info').empty();
        for(i=0;i<5;i++){
          $('.course-info').append("<tr><td>"+res[i]['CouNo']+"</td><td>"+res[i]['CouName']+"</td><td>"+res[i]['Kind']+"</td><td>"+res[i]['Credit']+"</td><td>"+res[i]['Teacher']+"</td><td>"+res[i]['SchoolTime']+"</td><td><a href=info.html?course="+res[i]['CouNo']+" class='detail'>查看</a></td></tr>");
        }
      },
      error: function (err) {
        console.log('请求失败')
      }
    });
  })

})